package com.wht.service;

import com.wht.domain.Admin;
import com.wht.mapper.AdminMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author wanghaotian
 * time:2022/11/24,0024 21:08
 * description:
 */

public class AdminLoginServiceImpl implements AdminLoginService {
    SqlSessionFactory factory = null;
    SqlSession session = null;
    @Override
    public Admin findAdmin(String username, String password) {
        try {
            InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
            factory = new SqlSessionFactoryBuilder().build(is);
            session = factory.openSession();
            AdminMapper mapper = session.getMapper(AdminMapper.class);
            Admin admin = mapper.findAdmin(username, password);
            return admin;
        } catch (Exception e) {
            return null;
        }
    }
}
